<template>
	<view class="main">
		<u-navbar title="消息" :autoBack="true" :placeholder="true" :titleStyle="state.titleStyle" :height="40"
			bgColor="#F5F5F5">
		</u-navbar>
		<scroll-view scroll-y="true" lower-threshold="80" @scrolltolower="getGoodsList" class="content" v-if="state.list.length>0">
			<block v-if="state.list.length!=0">
				<!-- <view v-for="(v,k) in state.list">{{v.user_info}}</view> -->
			<view class="xin" v-for="(v,k) in state.list" @click="goInfo(v.user_info.id,v.user_info.nickname,v.user_info.avatar)">
				<view class="teones">
					<image :src="v.avatar" mode=""></image>
					<view class="rihgt">
						<view class="tname">
							{{v.user_info.nickname}}
						</view>
						<view class="xiao">
							{{v.content}}
						</view>
					</view>
				</view>
				<view class="times">
					{{v.update_time_text}}
				</view>
			</view>
			</block>
		</scroll-view>
		<view class="wu" v-else>
			<image :src="state.url+'/useimage/chat_image.jpg'" mode=""></image>
			<!-- <image src="https://laiyu.1122334455.cn/useimage/chat_image.jpg" mode=""></image> -->
			<view class="cnei"> 暂无消息</view>
		</view>
	</view>	
</template>

<script setup>
	import {
		ref,
		reactive,
	} from 'vue';
	import sheep from '@/sheep';
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	const state = reactive({
		list:[],
		pageSize:10,
		page:1,
		hasMore:true,
		isLoad:false,
		url:'',
	});
	onShow((options) => {
		state.url = import.meta.env.BUZHENG_BASE_URL
		newsDatas()
	});
	function goInfo(id,name,img){
		uni.navigateTo({
			url:"/pages/news/news?userId="+id+'&username='+name+'&userimg='+img
		})
	}
	// 倒计时
	function getLeft(){
		uni.navigateBack({
			delta:1,//返回层数，2则上上页
		})
	}
	function select(e) {
		this.tabed = e
	}
	function newsDatas(){
		state.page=1
		state.hasMore=true
		state.isLoad=false
		state.list=[]
		getGoodsList()
	}
	async function getGoodsList(){
		if(state.isLoad) return false
		if(!state.hasMore) return false
		state.isLoad=true
		const {code,data} = await sheep.$api.zqzApi.newsList({
			token:uni.getStorageSync('token'),
			page:state.page,
			limit:state.pageSize,
		})
		if (code == 1) {
			let list = []
			for(let i=0;i<data.length;i++){
				if(data[i].user_info){
					list.push(data[i])
				}
			}
			let hasmore = list.length===state.pageSize
			list = state.list.concat(list)
			state.hasMore = hasmore
			state.list = list
			state.isLoad = false
			state.page = state.page+1
		}
	}
</script>
<style  lang="scss">
	.wu{
		text-align: center;
		padding:20rpx;
	    padding-top:200rpx;
		image{
			width:340rpx;
			height: 284rpx;
		}
		.cnei{
			line-height: 80rpx;
			font-size:28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
		}
		.lian{
			margin: 10rpx auto 0;
			width: 400rpx;
			height:96rpx;
			line-height: 96rpx;
			background: #1BDDD0;
			border-radius:54rpx;
			color: #fff;
			font-size: 32rpx;
		}
		
	}
	.content{width: 100%; height:calc(100% - 100rpx);margin-top: 20rpx;}
    page {
		height: 100%;
		width: 100%;
		background-color: #F5F5F5;
		.main {
			height: 100%;
			width: 100%;
			background-color: #F5F5F5;
			.xin{
				width:calc(100% - 104rpx);
				padding:24rpx;
				margin:24rpx auto 0;
				overflow: hidden;
				background: #fff;
				border-radius: 24rpx;
				display: flex;
				justify-content:space-between;
				.times{
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #999999;  
				}
				.teones{
					display: flex;
					width: 50%;
					.rihgt{
						width:calc(100% - 90rpx);
						.tname{
							font-size:32rpx;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #333333;
							margin-bottom: 10rpx;
						}
						.xiao{
							width: 100%;
							overflow: hidden;
							font-size: 24rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #666666;
							 display: -webkit-box;
							  -webkit-box-orient: vertical;
							  -webkit-line-clamp: 1;
						}
					}
					image{
						width:80rpx;
						height:80rpx;
						margin-right: 20rpx;
						border-radius: 50%;
						background: #f7f7f7;
					}
				}
			}
		}
	}
	.content .xin:nth-child(1){margin-top: 0;}
	

</style>
